using MicroMsg.Common.Utils;
using MicroMsg.UI.Util;
using System;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
namespace MicroMsg.UI.UserContrl
{
	public class UrlProcess : BaseInlineProcess
	{
		private const string PATTERN_STRINGS = "<a.+?href\\s*=\\s*\"\\s*(.+?)\\s*\"\\s*>(.+?)</a>";
		public const string BUILTIN_SEND_VERIFY_REQUEST = "weixin://findfriend/verifycontact";
		protected override int GetProbablyStartPos(string text, int startIndex)
		{
			if (string.IsNullOrEmpty(text))
			{
				return -1;
			}
			if (text.get_Length() <= startIndex)
			{
				return -1;
			}
			string text2 = text.Substring(startIndex, text.get_Length() - startIndex);
			Match match = Regex.Match(text2, "<a.+?href\\s*=\\s*\"\\s*(.+?)\\s*\"\\s*>(.+?)</a>");
			if (match.get_Success())
			{
				return match.get_Index() + startIndex;
			}
			return -1;
		}
		protected override Inline GetCurrentElement(string text, int startIndex, ref int elementLen, ref string elementStr)
		{
			if (startIndex < 0)
			{
				return null;
			}
			if (text.get_Length() <= startIndex)
			{
				return null;
			}
			string text2 = text.Substring(startIndex, text.get_Length() - startIndex);
			Match match = Regex.Match(text2, "<a.+?href\\s*=\\s*\"\\s*(.+?)\\s*\"\\s*>(.+?)</a>");
			if (match.get_Success())
			{
				if (match.get_Index() != 0)
				{
					return null;
				}
				if (match.get_Groups() != null && match.get_Groups().get_Count() >= 3)
				{
					UrlInfo urlInfo = new UrlInfo();
					urlInfo.allString = match.get_Groups().get_Item(0).get_Value();
					urlInfo.href = match.get_Groups().get_Item(1).get_Value();
					urlInfo.string_0 = match.get_Groups().get_Item(2).get_Value();
					elementStr = match.get_Value();
					elementLen = match.get_Value().get_Length();
					InlineUIContainer inlineUIContainer = new InlineUIContainer();
					HyperlinkButton hyperlinkButton = new HyperlinkButton();
					hyperlinkButton.set_FontSize(22.0);
					hyperlinkButton.set_Style((Style)Application.get_Current().get_Resources().get_Item("LinkStyle"));
					hyperlinkButton.set_Foreground(new SolidColorBrush(Color.FromArgb(255, 0, 0, 255)));
					hyperlinkButton.set_Margin(new Thickness(2.0, 0.0, 2.0, -6.0));
					hyperlinkButton.set_Content(urlInfo.string_0);
					hyperlinkButton.add_Click(new RoutedEventHandler(this.newUrlButton_Click));
					hyperlinkButton.set_Tag(urlInfo);
					inlineUIContainer.set_Child(hyperlinkButton);
					return inlineUIContainer;
				}
			}
			elementLen = 0;
			elementStr = null;
			return null;
		}
		private void newUrlButton_Click(object sender, RoutedEventArgs e)
		{
			HyperlinkButton hyperlinkButton = sender as HyperlinkButton;
			if (hyperlinkButton == null)
			{
				return;
			}
			UrlInfo urlInfo = hyperlinkButton.get_Tag() as UrlInfo;
			if (urlInfo == null)
			{
				return;
			}
			Log.smethod_5("UrlProcess", string.Concat(urlInfo));
			ChatPageCtrl basePage = this.getBasePage();
			if (basePage == null)
			{
				return;
			}
			if (urlInfo.href == "weixin://findfriend/verifycontact")
			{
				basePage.ValidToFriend();
			}
		}
		private ChatPageCtrl getBasePage()
		{
			return ChatContainerPage.tryGetCuChatPage();
		}
	}
}
